﻿using log4net;
using log4net.Config;
using log4net.Layout;
using log4net.Repository.Hierarchy;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
[assembly: XmlConfigurator(ConfigFile = "Kimd.config", Watch = true)]

namespace ZeroBug.EasyFlow.Core
{
    public class LogHelper
    {
        private readonly log4net.ILog appLog = LogManager.GetLogger("App");
        private readonly log4net.ILog plugginLog = LogManager.GetLogger("Pluggin");

        public LogHelper()
        {
        }

        public ILog GetLog(string logName)
        {
            return LogManager.GetLogger(logName);
        }

        public void Log(LogSource source, string message, MessageLevel level, Exception exception = null)
        {
            ILog log = null;
            switch(source)
            {
                case LogSource.App:
                    log = appLog;
                    break;
                case LogSource.Pluggin:
                    log = plugginLog;
                    break;
            }
            switch(level)
            {
                case MessageLevel.Error:
                    log.Error($"[{source}] {message}", exception);
                    break;
                case MessageLevel.Warn:
                    log.Warn($"[{source}] {message}");
                    break;
                case MessageLevel.Log:
                    log.Info($"[{source}] {message}");
                    break;
            }
        }
    }
    public enum LogSource
    {
        App,
        Pluggin,
    }
    public enum MessageLevel
    {
        Log,
        Warn,
        Error
    }
 }
